package specificGameObject;

import component.*;
import gameObject.*;
import system.*;
import vector.*;

public class Claw extends GameObject
{
	private Rope rope;
	public DraggableObject draggableObject; 
	private GameManager gameManager;
	
	public Claw(Vector2 _position) 
	{
		super("Claw", _position);
		gameManager = (GameManager) ServiceLocator.instance().getService(EService.GameManager);
		addSpriteRenderer("Image/claw.png", new Vector2(50,30), 100);
		addBoxCollider(new Vector2(0,0), new Vector2(50,30), Layer.Claw, Layer.DragbleObject);
		rope = (Rope) Game.instance().find("Rope");
	}
	
	@Override
	public void fixedUpdate() 
	{
		setPosition(new Vector2(rope.getEndPosition().x-25,rope.getEndPosition().y));
		if(draggableObject!= null)
			draggableObject.absorb(this);
	}
	
	public void onReach()
	{
		if(draggableObject!= null)
		{
			draggableObject.setActive(false);
			gameManager.setPoint(gameManager.getPoint()+draggableObject.price);
			draggableObject = null;
		}
	}
	
	@Override
	public void onCollide(BoxCollider collider) 
	{
		if(rope.getEState() == EState.Elongate)
		{
			draggableObject = (DraggableObject)collider.getGameObject();
			rope.setDragSpeed(draggableObject.getDragSpeed());
			rope.setEState(EState.Shorten);
		}
	}
}
